<?php
/**
* @desc 私人之旅表单处理
* @author kevin.wang
* @date 2015-01-01 12:00:00
**/
class PtravelForm extends BaseForm
{
	public $ptravel_keywords;
	public $goods_id;
	public $is_open;
	public $sort;
	public $intro;
	public $dinner;
	public $transport;
	public $ptravel_url;
	public $is_show;
	//表单规则
	public function rules()
	{
		return array(
			array('ptravel_keywords, sort, goods_id, is_open, ptravel_url', 'required', 'message'=>'必填字段不能为空'),
			array('ptravel_keywords', 'unique' , 'on'=>'add', 'className'=>'Ptravel', 'message'=>'私家之旅名称已存在'),
			array('sort, goods_id', 'numerical', 'message'=>'排序必须为数字'),
			array('is_show, is_open', 'boolean', 'message'=>'是否显示为布尔值'),
			array('transport','default', 'setOnEmpty'=>true, 'value'=>''),
			array('dinner','default', 'setOnEmpty'=>true, 'value'=>''),
			array('intro','default', 'setOnEmpty'=>true, 'value'=>''),
		);
	}
	//写入数据
	public function saveData(){
		$model = new Ptravel;
		$userInfo = json_decode(Yii::app()->session['userinfo'], true);
		$data = $this->attributes;
		$data['author'] = $userInfo['username'];
		return $model->insertPtravel($data);
	}
	//修改数据
	public function editData($id){
		$model = new Ptravel;
		return $model->editPtravel($id, $this->attributes);
	}
}
